package jscinttools.utilities.aidautilities;

import jscinttools.utilities.aidautilities.AidaFactories;
import hep.aida.*;
import java.io.*;
import java.lang.System;

/**
 *  Read an Aida File to the ITree and the other IManagedObject
 *
 *@author     Marc-Antoine Verdier
 *@created    6 novembre 2008
 */
public class AidaFileReader implements AidaFactories
{
	private String fullFileName;


	///**  Constructor for the AidaFileReader object */
	//public AidaFileReader() { }


	/**
	 *  Constructor for the AidaFileReader object
	 *
	 *@param  pathName                   The path of the Aida file
	 *@param  fileName                   The name of the Aida File
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public AidaFileReader(String pathName, String fileName)
			 throws FileNotFoundException, IOException
	{
		this(pathName + File.separator + fileName);
	}


	/**
	 *  Constructor for the AidaFileReader object
	 *
	 *@param  fullFileName               The full name of the Aida file (path
	 *      +name)
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public AidaFileReader(String fullFileName)
			 throws FileNotFoundException, IOException
	{
		this.fullFileName = fullFileName;
		System.out.println("Reading Aida File: " + fullFileName);
	}


	/**
	 *  Grab the main ITree
	 *
	 *@return                            the main ITree
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ITree grabTree()
			 throws FileNotFoundException, IOException
	{
		//System.out.println(fullFileName);
		//return AidaFactories.TREE_FACTORY.createTree(fullFileName.split(File.separator)[fullFileName.split(File.separator).length - 1] + ".aida", "xml", ITreeFactory.READONLY);
		return AidaFactories.TREE_FACTORY.createTree(fullFileName + ".aida", "xml", ITreeFactory.READONLY);
	}


	/**
	 *  Grab a sub ITree within the main ITree
	 *
	 *@param  treeFullName               The full path and name of the sub ITree
	 *@return                            The sub ITree
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ITree grabTree(String treeFullName)
			 throws FileNotFoundException, IOException
	{
		//return grabTree().findTree(treeFullName.split(File.separator)[fullFileName.split(File.separator).length - 1] + ".aida");
		//ITree ttree = grabTree();
		//return grabTree().findTree(treeFullName.split(File.separator)[fullFileName.split(File.separator).length - 1] + ".aida");
		return AidaFactories.TREE_FACTORY.createTree(fullFileName + ".aida", "xml", ITreeFactory.READONLY);
	}


	/**
	 *  Grab a ITuple inside a ITree
	 *
	 *@param  tupleFullName              The full path and name of the ITuple in
	 *      the ITree
	 *@param  tree                       The ITree
	 *@return                            The ITuple
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static ITuple grabTuple(String tupleFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding ITuple: " + tupleFullName);
		return (ITuple) tree.find(tupleFullName);
	}


	/**
	 *  Grab a ITuple in the main ITree
	 *
	 *@param  tupleFullName              The full path and name of the ITuple
	 *      inside the main ITree
	 *@return                            The ITuple
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ITuple grabTuple(String tupleFullName)
			 throws FileNotFoundException, IOException
	{
		return grabTuple(tupleFullName, grabTree());
	}


	/**
	 *  Grab a ITuple in a sub ITree
	 *
	 *@param  tupleFullName              The full path and name of the ITuple
	 *      inside the sub ITree
	 *@param  treeFullName               The full path and name of the sub ITree
	 *@return                            The ITuple
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ITuple grabTuple(String tupleFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabTuple(tupleFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  dpsFullName                Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IDataPointSet grabDPS(String dpsFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IDataPointSet: " + dpsFullName);
		return (IDataPointSet) tree.find(dpsFullName);
	}


	/**
	 *  Grab a IDataPointSet in the main ITree
	 *
	 *@param  dpsFullName                The full path and name of the
	 *      IDataPointSet inside the main ITree
	 *@return                            The IDataPointSet
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IDataPointSet grabDPS(String dpsFullName)
			 throws FileNotFoundException, IOException
	{
		return grabDPS(dpsFullName, grabTree());
	}


	/**
	 *  Grab a IDataPointSet in a sub ITree
	 *
	 *@param  dpsFullName                The full path and name of the
	 *      IDataPointSet inside the sub ITree
	 *@param  treeFullName               The full path and name of the sub ITree
	 *@return                            The IDataPointSet
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IDataPointSet grabDPS(String dpsFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabDPS(dpsFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IHistogram1D grabHisto1D(String histoFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IHistogram1D: " + histoFullName);
		return (IHistogram1D) tree.find(histoFullName);
	}


	/**
	 *  Grab a IHistogram1D in the main ITree
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@return                            The IDataPointSet
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IHistogram1D grabHisto1D(String histoFullName)
			 throws FileNotFoundException, IOException
	{
		return grabHisto1D(histoFullName, grabTree());
	}


	/**
	 *  Grab a IHistogram1D in a sub ITree
	 *
	 *@param  treeFullName               Description of the Parameter
	 *@param  histoFullName              Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IHistogram1D grabHisto1D(String histoFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabHisto1D(histoFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IHistogram2D grabHisto2D(String histoFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IHistogram2D: " + histoFullName);
		return (IHistogram2D) tree.find(histoFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IHistogram2D grabHisto2D(String histoFullName)
			 throws FileNotFoundException, IOException
	{
		return grabHisto2D(histoFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IHistogram2D grabHisto2D(String histoFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabHisto2D(histoFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IHistogram3D grabHisto3D(String histoFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IHistogram3D: " + histoFullName);
		return (IHistogram3D) tree.find(histoFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IHistogram3D grabHisto3D(String histoFullName)
			 throws FileNotFoundException, IOException
	{
		return grabHisto3D(histoFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  histoFullName              Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IHistogram3D grabHisto3D(String histoFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabHisto3D(histoFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cloudFullName              Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static ICloud2D grabCloud2D(String cloudFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding ICloud2D: " + cloudFullName);
		return (ICloud2D) tree.find(cloudFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cloudFullName              Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ICloud2D grabCloud2D(String cloudFullName)
			 throws FileNotFoundException, IOException
	{
		return grabCloud2D(cloudFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cloudFullName              Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ICloud2D grabCloud2D(String cloudFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabCloud2D(cloudFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cloudFullName              Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static ICloud3D grabCloud3D(String cloudFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding ICloud3D: " + cloudFullName);
		return (ICloud3D) tree.find(cloudFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cloudFullName              Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ICloud3D grabCloud3D(String cloudFullName)
			 throws FileNotFoundException, IOException
	{
		return grabCloud3D(cloudFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  cloudFullName              Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public ICloud3D grabCloud3D(String cloudFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabCloud3D(cloudFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  profileFullName            Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IProfile1D grabProfile1D(String profileFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IProfile1D: " + profileFullName);
		return (IProfile1D) tree.find(profileFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  profileFullName            Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IProfile1D grabProfile1D(String profileFullName)
			 throws FileNotFoundException, IOException
	{
		return grabProfile1D(profileFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  profileFullName            Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IProfile1D grabProfile1D(String profileFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabProfile1D(profileFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  profileFullName            Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IProfile2D grabProfile2D(String profileFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IProfile2D: " + profileFullName);
		return (IProfile2D) tree.find(profileFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  profileFullName            Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IProfile2D grabProfile2D(String profileFullName)
			 throws FileNotFoundException, IOException
	{
		return grabProfile2D(profileFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  profileFullName            Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IProfile2D grabProfile2D(String profileFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabProfile2D(profileFullName, grabTree(treeFullName));
	}


	/**
	 *  Description of the Method
	 *
	 *@param  funcFullName               Description of the Parameter
	 *@param  tree                       Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public static IFunction grabFunction(String funcFullName, ITree tree)
			 throws FileNotFoundException, IOException
	{
		System.out.println("Finding IFunction: " + funcFullName);
		return (IFunction) tree.find(funcFullName);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  funcFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IFunction grabFunction(String funcFullName)
			 throws FileNotFoundException, IOException
	{
		return grabFunction(funcFullName, grabTree());
	}


	/**
	 *  Description of the Method
	 *
	 *@param  funcFullName               Description of the Parameter
	 *@param  treeFullName               Description of the Parameter
	 *@return                            Description of the Return Value
	 *@exception  FileNotFoundException  Description of the Exception
	 *@exception  IOException            Description of the Exception
	 */
	public IFunction grabFunction(String funcFullName, String treeFullName)
			 throws FileNotFoundException, IOException
	{
		return grabFunction(funcFullName, grabTree(treeFullName));
	}

	///**
	// *  Gets the fullFileName attribute of the AidaFileReader object
	// *
	// *@return    The fullFileName value
	// */
	//public String getFullFileName()
	//{
	//	return fullFileName;
	//}
	//
	//
	///**
	// *  Sets the fullFileName attribute of the AidaFileReader object
	// *
	// *@param  fullFileName  The new fullFileName value
	// */
	//public void setFullFileName(String fullFileName)
	//{
	//	this.fullFileName = fullFileName;
	//}
}

